package com.iflytek.exam.controller;

import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.iflytek.exam.domain.TbAll;
import com.iflytek.exam.domain.TbQuestionSummary;
import com.iflytek.exam.service.ITbAllService;
import com.iflytek.exam.service.ITbQuestionSummaryService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.iflytek.common.annotation.Log;
import com.iflytek.common.core.controller.BaseController;
import com.iflytek.common.core.domain.AjaxResult;
import com.iflytek.common.enums.BusinessType;
import com.iflytek.exam.domain.Choice;
import com.iflytek.exam.service.IChoiceService;
import com.iflytek.common.utils.poi.ExcelUtil;
import com.iflytek.common.core.page.TableDataInfo;

/**
 * 单选题添加Controller
 *
 * @author Dogdog
 * @date 2024-07-07
 */
@RestController
@RequestMapping("/exam/choice")
public class ChoiceController extends BaseController
{
    @Autowired
    private IChoiceService choiceService;
    @Autowired
    private ITbAllService iTbAllService;

    @Autowired
    private ITbQuestionSummaryService iTbQuestionSummaryService;

    @PreAuthorize("@ss.hasPermi('exam:choice:get')")
    @GetMapping("/getAllSummary")
    public TableDataInfo getSummary(TbQuestionSummary tbQuestionSummary)
    {
        ArrayList arrayList = new ArrayList();
        List<TbQuestionSummary> list = iTbQuestionSummaryService.selectTbQuestionSummaryList(tbQuestionSummary);
        return getDataTable(list);
    }

    /**
     * 查询单选题添加列表
     */
    @PreAuthorize("@ss.hasPermi('exam:choice:list')")
    @GetMapping("/list")
    public TableDataInfo list(Choice choice)
    {
        startPage();
        List<Choice> list = choiceService.selectChoiceList(choice);
        return getDataTable(list);
    }

    /**
     * 导出单选题添加列表
     */
    @PreAuthorize("@ss.hasPermi('exam:choice:export')")
    @Log(title = "单选题添加", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Choice choice)
    {

        List<Choice> list = choiceService.selectChoiceList(choice);
        ExcelUtil<Choice> util = new ExcelUtil<Choice>(Choice.class);
        util.exportExcel(response, list, "单选题添加数据");

    }

    /**
     * 获取单选题添加详细信息
     */
    @PreAuthorize("@ss.hasPermi('exam:choice:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(choiceService.selectChoiceById(id));
    }

    /**
     * 新增单选题添加
     */
    @PreAuthorize("@ss.hasPermi('exam:choice:add')")
    @Log(title = "单选题添加", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Choice choice)
    {
        choiceService.insertChoice(choice);
        TbAll tbAll = new TbAll();
        Long allId = choice.getId();// 获取单选题id
        Long quBankId = choice.getQuBankId();// 获取题库id
        String title = choice.getTitle();// 获取题目
        Integer type = choice.getType();// 获取题型
        Integer degree = choice.getDegree();// 获取难度
        String categoryFirst = choice.getCategoryFirst();
        String categorySecond = choice.getCategorySecond();
        String categoryThrid = choice.getCategoryThrid();
        tbAll.setAllId(allId);
        tbAll.setQuBankId(quBankId);
        tbAll.setTitle(title);
        tbAll.setType(type);
        tbAll.setDegree(degree);
        tbAll.setCategoryFirst(categoryFirst);
        tbAll.setCategorySecond(categorySecond);
        tbAll.setCategoryThrid(categoryThrid);
        return toAjax(iTbAllService.insertTbAll(tbAll));

    }

    /**
     * 修改单选题添加
     */
    @PreAuthorize("@ss.hasPermi('exam:choice:edit')")
    @Log(title = "单选题添加", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Choice choice)
    {
        return toAjax(choiceService.updateChoice(choice));
    }

    /**
     * 删除单选题添加
     */
    @PreAuthorize("@ss.hasPermi('exam:choice:remove')")
    @Log(title = "单选题添加", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(choiceService.deleteChoiceByIds(ids));
    }
}
